<?php


/* @var $model Book */
/* @var $is_favorite */
/* @var $is_score */

/* @var $this View */

use app\helpers\AppHelper;
use app\helpers\BookHelper;
use app\models\Book;
use app\models\Setting;
use app\widgets\CommentWidget;
use app\widgets\RelationWidget;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\View;

$items = $model->items;
$index_item = current($items);
$lastItem = end($items);
?>
<div class="panel book" id="<?= $model['id']; ?>">
    <div class="panel-body columns">
        <div class="column col-8 col-md-12">
            <div class="tile">
                <div class="tile-icon">
                    <img class="book-thumbnail mr-3" src="<?= AppHelper::formatImage($model['thumbnail']); ?>" alt="<?= Html::encode($model['title']); ?>">
                </div>
                <div class="tile-content">
                    <div class="tile-title d-flex">
                        <h4 class="col-mr-auto"><?= Html::encode($model['title']); ?></h4>
                        <span class="font-1"><em class="text-muted">更至: </em><a href="<?= Url::to(['comic/item', 'id' => $model['id'], 'itemId' => $lastItem['id']]); ?>"><?= $lastItem['name']; ?></a></span>
                    </div>
                    <div class="tile-title d-flex">
                        <div class="book-tag col-mr-auto">
                            <?= BookHelper::formatTag($model->tags); ?>
                        </div>
                        <div class="book-score">
                            <span><?= $is_score ? '您的评分：' : '请您评分：' ; ?></span>
                            <span data-href="<?= Url::to(['user/save-score', 'id' => $model['id']]); ?>" data-score="<?= $is_score ? $is_score : 0; ?>" class="raty mr-2" data-only="<?= $is_score ? 'true' : 'false'; ?>"></span>
                            <?php if($model->score > 0): ?>
                                <span>评分：<em><?= $model->score; ?></em></span>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="tile-title book-view">
                        <?php if($model->author_id): ?>
                        <label class="label mx-2"><em><?= $model->author['name']; ?></em></label>
                        <?php endif; ?>
                        <label class="label mx-2">人气:<em><?= AppHelper::formatNumber($model->view_count); ?></em></label>
                        <label class="label ml-2">收藏:<em><?= $model->favorite_count; ?></em></label>

                    </div>
                    <div class="tile-title book-desc">
                        <?= Html::encode($model['description']); ?>
                    </div>
                    <div class="d-flex">
                        <a class="btn btn-xl btn-danger mr-2" href="<?= Url::to(['comic/item', 'id' => $model['id'], 'itemId' => $index_item['id']]); ?>"><i class="icon-book mr-2"></i>继续阅读</a>
                        <a class="btn btn-xl btn-dark favorite" href="javascript:void(0);" data-href="<?= Url::to(['user/save-favorite', 'id' => $model['id']]); ?>"><i class="icon-star-o mr-2"></i><span><?= $is_favorite ? '取消收藏' : '收藏'; ?></span></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="column col-4 hide-md">
            <?= Setting::get('ad_detail'); ?>
        </div>
    </div>
</div>

<div class="panel book-item">
    <div class="panel-header">
        <div class="d-flex">
            <h4 class="col-mr-auto">章节列表</h4>
            <div class="book-item-action">
                <a href="javascript:void(0);" class="sort hover"><i class="icon-up"></i>正序</a>
                <a href="javascript:void(0);" class="sort d-none hover"><i class="icon-down"></i>倒序</a>
            </div>
        </div>
    </div>
    <div class="panel-body book-item-list">
        <div class="columns">
            <?php foreach ($items as $i => $item): ?>
                <div class="column col-1 col-md-2 col-sm-3">
                    <a data-tooltip="<?= BookHelper::getBookItemTitle($item); ?>" title="<?= BookHelper::getFullBookItemName($item); ?>" class="book-item-btn tooltip tooltip-top" href="<?= Url::to(['comic/item', 'id' => $model['id'], 'itemId' => $item['id']]); ?>"><?= BookHelper::getBookItemName($item); ?>
                        <?= $item['name'] == $model['last_item'] ? '<span class="new"></span>' : ''; ?>
                    </a>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</div>

<div class="panel book-relation">
    <div class="panel-header"><h4>猜你喜欢</h4></div>
    <div class="panel-body ">
        <div class="columns">
            <?= RelationWidget::widget(compact('model')); ?>
        </div>
    </div>
</div>

<?= CommentWidget::widget(compact('model')); ?>

